package com.atguigu.yygh.host.api.controller;

import com.atguigu.yygh.common.R;
import com.atguigu.yygh.host.service.DepartmentService;
import com.atguigu.yygh.host.service.HospitalService;
import com.atguigu.yygh.host.service.ScheduleService;
import com.atguigu.yygh.model.hosp.Hospital;
import com.atguigu.yygh.model.hosp.Schedule;
import com.atguigu.yygh.vo.hosp.DepartmentVo;
import com.atguigu.yygh.vo.hosp.HospitalQueryVo;
import com.atguigu.yygh.vo.hosp.ScheduleOrderVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

/**
 * @author DongYu Zhou
 * @date 2022/6/28 22:18
 */
@Api(tags = "医院显示接口")
@RestController
@RequestMapping("/api/hosp/hospital")
public class HospitalApiController {

    @Autowired
    private HospitalService hospitalService;
    @Autowired
    private DepartmentService departmentService;
    @Autowired
    private ScheduleService scheduleService;

    /**
     * 带条件获取分页列表
     * @param page
     * @param limit
     * @param hospitalQueryVo
     * @return
     */
    @ApiOperation(value = "带条件获取分页列表")
    @GetMapping("{page}/{limit}")
    public R index(@PathVariable("page") Integer page, @PathVariable("limit") Integer limit, HospitalQueryVo hospitalQueryVo) {

        Page<Hospital> pages = hospitalService.index(page, limit, hospitalQueryVo);
        return R.ok().data("pages", pages);
    }

    /**
     * 根据医院名称获取医院列表
     * @param hosname
     * @return
     */
    @ApiOperation(value = "根据医院名称获取医院列表")
    @GetMapping("findByHosname/{hosname}")
    public R findByHosname(@PathVariable("hosname") String hosname) {
        List<Hospital> list = hospitalService.getHosnameLike(hosname);
        return R.ok().data("list", list);

    }

    /**
     * 获取科室列表 -> hoscode
     * @param hoscode
     * @return
     */
    @ApiOperation(value = "获取科室列表")
    @GetMapping("department/{hoscode}")
    public R index(@PathVariable("hoscode") String hoscode) {
        List<DepartmentVo> depVoList = departmentService.getDepVoList(hoscode);
        return R.ok().data("list", depVoList);
    }

    /**
     * 根据医院编码获取医院详情 ->根据医院编码获取医院详情
     * @param hoscode
     * @return
     */
    @ApiOperation(value = "根据医院编码获取医院详情")
    @GetMapping("{hoscode}")
    public R item(@PathVariable("hoscode") String hoscode) {
        Map<String, Object> map = hospitalService.getDepVoInfoList(hoscode);
        return R.ok().data(map);
    }

    /**
     * 获取可预约排班统计数据
     * @param page
     * @param limit
     * @param hoscode
     * @param depcode
     * @return
     */
    @ApiOperation(value = "获取可预约排班统计数据")
    @GetMapping("auth/getBookingScheduleRule/{page}/{limit}/{hoscode}/{depcode}")
    public R getBookingSchedule(@PathVariable Integer page, @PathVariable Integer limit, @PathVariable String hoscode, @PathVariable String depcode) {
        Map<String, Object> map = scheduleService.getBookingchedule(page, limit, hoscode, depcode);
        return R.ok().data(map);
    }

    /**
     * 获取排班数据
     * @param hoscode
     * @param depcode
     * @param workDate
     * @return
     */
    @ApiOperation(value = "获取排班数据")
    @GetMapping("auth/findScheduleList/{hoscode}/{depcode}/{workDate}")
    public R findScheduleList(@PathVariable String hoscode, @PathVariable String depcode, @PathVariable String workDate) {
        List<Schedule> scheduleList = scheduleService.getScheduleDetail(hoscode, depcode, workDate);
        return R.ok().data("scheduleList", scheduleList);
    }

    /**
     * 根据排班id获取排班详情
     * @param id
     * @return
     */
    @ApiOperation(value = "根据排班id获取排班详情")
    @GetMapping("getSchedule/{id}")
    public R findScheduleById(@PathVariable String id) {
        Schedule schedule = scheduleService.findScheduleById(id);
        return R.ok().data("schedule", schedule);
    }

    /**
     * 远程调用 根据排班id获取预约下单数据
     * @param scheduleId
     * @return
     */
    @ApiOperation(value = "根据排班id获取预约下单数据")
    @GetMapping("inner/getScheduleOrderVo/{scheduleId}")
    public ScheduleOrderVo getScheduleOrderVo(
            @PathVariable("scheduleId") String scheduleId) {
        ScheduleOrderVo scheduleOrderVo =
                scheduleService.getScheduleOrderVo(scheduleId);
        return scheduleOrderVo;

    }

}
